package com.nxk.modules.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nxk.modules.content.dao.ConCultureDao;
import com.nxk.modules.content.entity.ConCulture;
import com.nxk.modules.content.service.ConCultureService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ConCultureServiceImpl extends ServiceImpl<ConCultureDao, ConCulture> implements ConCultureService {
     @Override
     @Transactional(readOnly = false)
    public boolean save(ConCulture conCulture) {
        if (StringUtils.isNotBlank(conCulture.getId())) {
            return super.updateById(conCulture);
        } else {
            return super.save(conCulture);
        }
    }

    @Override
    public IPage<ConCulture> page(ConCulture conCulture) {
        Page<ConCulture> page = new Page<ConCulture>(conCulture.getPageNo(), conCulture.getPageSize());
        QueryWrapper<ConCulture> queryWrapper = new QueryWrapper<ConCulture>();
        if (StringUtils.isNotBlank(conCulture.getCultureTitle())) {
            queryWrapper.lambda().like(ConCulture::getCultureTitle, conCulture.getCultureTitle());
        }
        queryWrapper.orderByAsc("sort").in("status", 1, 2);
        IPage<ConCulture> result = super.page(page, queryWrapper);
        return result;

    }

    @Override
    @Transactional(readOnly = false)
    public boolean deleteById(String id) {
        return super.removeById(id);
    }

}
